<?php
	require "../database/mysql.class.php";
class userdao{	
	private $db;
	public function __construct(){
		$this->db=new mysql();
	}
	//验证登入用户名是否存在
	public function regcheck($name){
		$sql="select * from users where uname='{$name}';";
        $rs=$this->db->query($sql);
        if (empty($rs)){
			return 0;
		}
		return  1;	         
	}
	
	//用户注册
	public function zhuce($name,$pwd){
		$sql="INSERT INTO users VALUES(null,'".$name."','".$pwd."','".$name."',1,100,null,null,0,now(),'可用','锁定');";
		$this->db->insert($sql);
		//error_log( $this->db->getid());
		return $this->db->getid();      
	}
	//用户登录
	public function login($name,$pwd){
		$sql="select * from users where uname='{$name}' and pwd='{$pwd}';";
		return $this->db->query($sql);		
	}
	//重新查询用户
	public function newlogin($userid){
		$sql="select * from users where id='{$userid}';";
		return $this->db->query($sql);
	}
	//初始化用户车辆
	public function ubike($uid){
		$sql="insert into user_bike(userid, bikeid) values(".$uid.",1);";
		//error_log($sql);
		return $this->db->insert($sql);	      
	}
	//初始化用户骑手
	public function urider($uid){
		$sql="insert into user_rider(userid, riderid) values(".$uid.",1);";
		return $this->db->insert($sql);	      
	}
	//初始化用户装备
	public function uequip($uid){
		$sql="insert into user_equip(userid, equipid) values(".$uid.",1);";
		return $this->db->insert($sql);	      
	}
	//初始化用户任务关卡
	public function umission($uid){
		$sql="insert into user_mission(userid, misionid) values(".$uid.",1);";
		return $this->db->insert($sql);	      
	}
	//游戏结束增加用户关卡
	public function overmiss($mission,$userid){
		$sql="insert into user_mission(misionid,userid) values(".$mission.",".$userid.");";
		return $this->db->insert($sql);	      
	}
	//游戏结束增加用户金币
	public function overcoin($coin,$userid){
		$sql="update users set price=".$coin." where id=".$userid.";";
		error_log($sql);
		return $this->db->update($sql);	      
	}
	//查询是否已解锁
	public function misscheck($mission,$userid){
		$sql="select * from user_mission where userid='.$userid.' and
		      misionid=".$mission.";";
		return $this->db->query($sql);		
	}
	//购买车手
	public function goubiker($userid,$riderid){
		$sql="insert into user_rider(userid,riderid) values(".$userid.",".$riderid.");";
		return $this->db->insert($sql);	    
	}
	//购买车辆
	public function goubike($userid,$riderid){
		$sql="insert into user_bike(userid,bikeid) values(".$userid.",".$riderid.");";
		return $this->db->insert($sql);	    
	}
	//购买装备
	public function gouequip($userid,$riderid){
		$sql="insert into user_equip(userid,equipid) values(".$userid.",".$riderid.");";
		return $this->db->insert($sql);	    
	}
	//订单——购买车手
	public function dinggoubiker($userid,$rname){
		$sql="insert into dingdang(uname,type,xiang,time) values(".$userid.",'购买骑手','购买了".$riderid."',now());";
		return $this->db->insert($sql);	    
	}
	//订单——购买车辆
	public function dinggoubike($userid,$rname){
		$sql="insert into dingdang(uname,type,xiang,time) values(".$userid.",'购买车辆','购买了".$riderid."',now());";
		return $this->db->insert($sql);	    
	}
	//订单——购买装备
	public function dinggouequip($userid,$rname){
		$sql="insert into dingdang(uname,type,xiang,time) values(".$userid.",'购买装备','购买了".$riderid."',now());";
		return $this->db->insert($sql);	    
	}
	//修改密码
	public function changepwd($repsw,$psw,$uname){
		$sql="update users set pwd='".$repsw."' where uname='".$uname."' and pwd='".$psw."' ;";
		return $this->db->update($sql);
	}
}
?>